package com.southwind.phone_store_demo.controller;

import com.southwind.phone_store_demo.dto.UserDTO;
import com.southwind.phone_store_demo.exception.PhoneException;
import com.southwind.phone_store_demo.form.OrderForm;
import com.southwind.phone_store_demo.form.UserForm;
import com.southwind.phone_store_demo.service.UserService;
import com.southwind.phone_store_demo.util.ResultVOUtil;
import com.southwind.phone_store_demo.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/user")
@Slf4j

public class UserHandler {
    @Autowired
    private UserService userService;

    @PostMapping(value = "/register")
    public ResultVO register(@RequestParam(value = "username",required = false) String username, @RequestParam(value = "password",required = false)String password, @RequestParam(value = "email",required = false)String email) {
        System.out.println("1234");
        System.out.println(email);
        UserDTO userDTO = new UserDTO();
        userDTO.setUsername(username);
        userDTO.setPassword(password);
        userDTO.setEmail(email);
        userService.register(userDTO);
        return ResultVOUtil.success(null);
    }

    @GetMapping("/login")
    public ResultVO login(@RequestParam(value = "username",required = false) String username, @RequestParam(value = "password",required = false)String password) {
        boolean result =  userService.queryByUsername(username, password);
        if (result==true){


            return ResultVOUtil.success("成功");

        }else{
            return ResultVOUtil.error("失败");
        }
    }
}